<?php
/*
	插件概览
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
if($_RQ['op']=='edit'){
	$return['templist']=$this->plugin_setting('img');
	$id=intval($_RQ['id']);
	$return['img']=array();	
	if($id){
		$item=pdo_get('jy_invitation_list',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['tem']=array();
		$item['data']=json_decode($item['data'],true);
		foreach($item['data'] as $v){		
			foreach($return['templist'] as $k=>$i){
				if($i['img']==$v){
					$return['templist'][$k]['on']=1;
				}
			}
		}
		
	}else{
		$item=array();
		//$item['templist']=array();
	}
	$return['setting']=cfc('jy_weishop')->plugin_setting('shopset');
	$item['text4']=$item['text4']?:'商城介绍';
	$item['text5']=$item['text5']?:$return['setting']['desc'];
	$return['item']=$item;	
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$list=array();
	$img=$this->plugin_setting('img');	
	foreach($postdata['data'] as $k=>$v){
		if($v['on']==1){
			$list[$k]=$v['img'];//未tomedia
		}
		$is=0;
		foreach($img as $i){
			if($i['img']==$v['img']){
				$is=1;
			}
		}
		if($is==0){
			$img[]=array('on'=>0,'img'=>$v['img']);	
			
		}
	}
	$this->plugin_setting('img',$img);
	$data=array(
		'status'=>1,
		'title'=>trim($postdata['title']),
		'data'=>json_encode($list),
		'text1'=>trim($postdata['text1']),
		'text2'=>trim($postdata['text2']),
		'text3'=>trim($postdata['text3']),
		'text4'=>trim($postdata['text4']),
		'text5'=>trim($postdata['text5']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_invitation_list',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('修改成功！');
	}else{
		$data['createtime']=time();
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_invitation_list',$data);
		exi('保存成功！');
	}
}
if($_RQ['op']=='qc'){
	$id=$_RQ['id'];
	if(!$id){
		exi('请选择活动卡！','error');
	}
	$path=ROOT_AT .'images/jy_invitation/' . $_SESSION['uniacid'].'/'.$id.'/';
	//file_put_contents(ROOT_D.'/11.TXT',$path);
	$handle = scandir($path);
	foreach($handle as $val){
    	//排除目录中的.和..
    	if($val !="." && $val !=".."){
    		//如果是文件直接删除
    		unlink($path.$val);
		}
   }
	exi('清除成功');
} 